package test3.main;

import test3.bean.Employee;
import test3.controller.PageController;
import test3.dao.EmployeeDao;
import test3.dao.impl.EmployeeDaoImpl;
import test3.main.Index;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JOptionPane;

public class DeleteAction implements ActionListener {

	Index index;

	private PageController controller;
	
	public DeleteAction(Index in) {
		index = in;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String select = e.getActionCommand();
		if(select == "query") {
			//获得id
			//
			String idStr=null;  //需要获取

			Integer id =null;

			try {
				id=Integer.parseInt(idStr);
			    Employee employee=controller.queryById(id);
			    if (employee!=null) {
					//查询到的数据
					String name = employee.getName();
					Integer age = employee.getAge();
					Integer sex = employee.getSex();  //性别   1为男   0为女

					//需要将员工的数据显示

				}else {
			    	//查询失败
					System.out.println("没有该员工的信息！");
				}

			}catch (Exception ee){
				System.out.println("请输入正确的数据！");
			}

		//	System.out.println("无删除功能实现");

		//	Employee employee=controller.queryById(id);

			//下面显示employee的数据

		}
		else if(select == "delete"){

			//获得id
			//
			//需要获取这个数据
			String idStr=null;
			Integer id =null;

			controller.delete(id);

			//删除之后的操作
			//

			Toolkit.getDefaultToolkit().beep();
			JOptionPane.showMessageDialog(null, "Delete success","Result",JOptionPane.PLAIN_MESSAGE);
		}
		else {
			index.card.show(index.panel, "welcome");
		}
	}



}
